<template>
<view class="map_container">
    <view class="map-input">
        <picker :range="poisData" :range-key="'name'" :value="index" @change="bindPickerChange">
            <view class="picker">{{poisData[index].name}}</view>
        </picker>
    </view>
</view>
</template>

<script>
// components/cmap/cmap.js
var amapFile = require("../../utils/amap-wx.js");

export default {
  data() {
    return {
      poisData: [],
      index: 0
    };
  },

  components: {},
  props: {},
  beforeMount: function () {
    var _this = this;

    var myAmapFun = new amapFile.AMapWX({
      key: '1fde56f1927c48a4ab60f5f4bd61f864'
    });
    myAmapFun.getPoiAround({
      success: function (data) {
        _this.setData({
          poisData: data.poisData
        });
      },
      fail: function (info) {
        //失败回调
        console.log(info);
      }
    });
  },
  methods: {
    bindPickerChange: function (e) {
      let index = e.detail.value;
      this.setData({
        index
      });
      this.$emit('getLocal', {
        detail: this.data.poisData[index]
      });
    }
  }
};
</script>
